<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* $Id: user.php 53 2012-04-03 15:02:56Z zengdong615@gmail.com $
*/
class User extends CI_Model
{
	
	function __construct()
	{
		parent::__construct();
	}

	function add($user)
	{
		$this->db->insert('user',$user);

		return  $this->get_max_id();
	}

	function get_max_id()
	{
		$this->db->select_max('use_rid');
		$query = $this->db->get('user');
		$row = $query->result();
		$row = $row[0];

		return $row->user_id;
	}

	function get_by_email($email)
	{
		$query = $this->db->get_where('user',array('email' => $email));

		$row = $query->result();
		if ($row) {
			$row = $row[0];
		}else{
			$row = NULL;
		}
		

		return $row;

	}

	function get_by_id($id='')
	{
		$this->db->select('name, email');
		$query = $this->db->get_where('user',array('user_id' => $id, 'state' => 1));

		$row = $query->result_array();
		if ($row) {
			$row = $row[0];
		}else{
			$row = NULL;
		}
		

		return $row;
	}
}